package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.orm.db.assit.QueryBuilder;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.PlanKeyDelData;

import java.util.List;

/**
 * Created by yanghaojie on 16/7/27.
 */
public class PlanKeyDelImpl implements PlanKeyDelDao {

    @Override
    public void addOrupdateKeyPlan(int userid, List<PlanKeyDelData> keyPlanData) {
        if (null != keyPlanData || keyPlanData.size() > 0)
            deleteByUserId(userid);
        DbHelp.insertAll(keyPlanData);
    }

    @Override
    public List<PlanKeyDelData> findPlanKeyByUserId(int userId) {
        QueryBuilder qb = new QueryBuilder(PlanKeyDelData.class).whereEquals(PlanKeyDelData.USER_ID, userId);
        return DbHelp.liteOrm.query(qb);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(PlanKeyDelData.class);
    }

    @Override
    public void deleteByUserId(int userId) {
        DbHelp.deleteWhere(PlanKeyDelData.class, PlanKeyDelData.USER_ID, new String[]{String.valueOf(userId)});
    }
}

